{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "Untitled3.ipynb",
      "provenance": [],
      "collapsed_sections": [],
      "toc_visible": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {
        "id": "qx6uOhxGzyTE"
      },
      "source": [
        "import torch\n",
        "import torchvision\n",
        "import torch.nn as nn\n",
        "import numpy as np"
      ],
      "execution_count": 1,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "zsW5C7yp1XP-"
      },
      "source": [
        "class Net(nn.Module):\n",
        "  def __init__(self):\n",
        "    super(Net, self).__init__()\n",
        "    self.connect1 = nn.Linear(1,6)\n",
        "    self.sigmod2 = nn.Sigmoid()\n",
        "    self.connect3 = nn.Linear(6,8)\n",
        "    self.sigmod4 = nn.Sigmoid()\n",
        "    self.connect5 = nn.Linear(8,16)\n",
        "    self.sigmod6 = nn.Sigmoid()\n",
        "    self.connect7 = nn.Linear(16,8)\n",
        "    self.connect8 = nn.Linear(8,2)\n",
        "  \n",
        "  def forward(self, x):\n",
        "    x = self.connect1(x)\n",
        "    x = self.sigmod2(x)\n",
        "    x = self.connect3(x)\n",
        "    x = self.sigmod4(x)\n",
        "    x = self.connect5(x)\n",
        "    x = self.sigmod6(x)\n",
        "    x = self.connect7(x)\n",
        "    x = self.connect8(x)\n",
        "    return nn.functional.log_softmax(x, dim=1)"
      ],
      "execution_count": 2,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "IxHFP1Zt9SCe"
      },
      "source": [
        "myNet = Net()"
      ],
      "execution_count": 3,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "NNxWvX2s9Zlp",
        "outputId": "4588d446-f99b-4de9-b04f-d4c487896cc7"
      },
      "source": [
        "myNet(torch.zeros(2,1))"
      ],
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[-0.7042, -0.6822],\n",
              "        [-0.7042, -0.6822]], grad_fn=<LogSoftmaxBackward0>)"
            ]
          },
          "metadata": {},
          "execution_count": 4
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "6bXHvzXh9cGp"
      },
      "source": [
        "def train(network, epoch=100000, batch=1000):\n",
        "  network.train()\n",
        "  optimizer = torch.optim.SGD(network.parameters(), lr=0.3)\n",
        "  cur_epoch = 0\n",
        "  while(cur_epoch < epoch):\n",
        "    input = torch.rand([batch,1])\n",
        "    ground_truth = torch.zeros([batch,1])\n",
        "    ground_truth[input>0.5] = 1.0\n",
        "    optimizer.zero_grad()\n",
        "    output = network(input)\n",
        "    loss = nn.functional.nll_loss(output, ground_truth.squeeze(1).long())\n",
        "    # print(input)\n",
        "    # print(ground_truth.squeeze(1).long())\n",
        "    # print(output[0:], loss)\n",
        "    # break\n",
        "    loss.backward()\n",
        "    optimizer.step()\n",
        "    cur_epoch = cur_epoch + 1\n",
        "    if cur_epoch % 200 == 0:\n",
        "      print(\"epoch:{} ; loss:{}\".format(cur_epoch, loss))"
      ],
      "execution_count": 5,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "3FHhRcW_-BF-",
        "outputId": "97fe1c45-87f6-45df-f7b2-10a2479f94b7"
      },
      "source": [
        "train(myNet)"
      ],
      "execution_count": 6,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "epoch:200 ; loss:0.6936331391334534\n",
            "epoch:400 ; loss:0.6930502653121948\n",
            "epoch:600 ; loss:0.6939948201179504\n",
            "epoch:800 ; loss:0.6931053400039673\n",
            "epoch:1000 ; loss:0.6929658055305481\n",
            "epoch:1200 ; loss:0.692674458026886\n",
            "epoch:1400 ; loss:0.6930409669876099\n",
            "epoch:1600 ; loss:0.6921197772026062\n",
            "epoch:1800 ; loss:0.6928079724311829\n",
            "epoch:2000 ; loss:0.693054735660553\n",
            "epoch:2200 ; loss:0.6917715668678284\n",
            "epoch:2400 ; loss:0.6916819214820862\n",
            "epoch:2600 ; loss:0.6897680759429932\n",
            "epoch:2800 ; loss:0.6823455691337585\n",
            "epoch:3000 ; loss:0.6263715028762817\n",
            "epoch:3200 ; loss:0.08895965665578842\n",
            "epoch:3400 ; loss:0.045885760337114334\n",
            "epoch:3600 ; loss:0.08409840613603592\n",
            "epoch:3800 ; loss:0.022105367854237556\n",
            "epoch:4000 ; loss:0.03266129270195961\n",
            "epoch:4200 ; loss:0.019752874970436096\n",
            "epoch:4400 ; loss:0.04894936829805374\n",
            "epoch:4600 ; loss:0.023481575772166252\n",
            "epoch:4800 ; loss:0.10813978314399719\n",
            "epoch:5000 ; loss:0.010935273952782154\n",
            "epoch:5200 ; loss:0.021206889301538467\n",
            "epoch:5400 ; loss:0.011654281988739967\n",
            "epoch:5600 ; loss:0.010710012167692184\n",
            "epoch:5800 ; loss:0.03633519262075424\n",
            "epoch:6000 ; loss:0.01055685430765152\n",
            "epoch:6200 ; loss:0.011715876869857311\n",
            "epoch:6400 ; loss:0.014575378969311714\n",
            "epoch:6600 ; loss:0.027915997430682182\n",
            "epoch:6800 ; loss:0.01124579831957817\n",
            "epoch:7000 ; loss:0.008517367765307426\n",
            "epoch:7200 ; loss:0.06565305590629578\n",
            "epoch:7400 ; loss:0.006953463889658451\n",
            "epoch:7600 ; loss:0.014420274645090103\n",
            "epoch:7800 ; loss:0.010033933445811272\n",
            "epoch:8000 ; loss:0.03258971497416496\n",
            "epoch:8200 ; loss:0.05588725209236145\n",
            "epoch:8400 ; loss:0.04190032184123993\n",
            "epoch:8600 ; loss:0.007002690806984901\n",
            "epoch:8800 ; loss:0.10693904757499695\n",
            "epoch:9000 ; loss:0.012739533558487892\n",
            "epoch:9200 ; loss:0.007456481456756592\n",
            "epoch:9400 ; loss:0.004678339697420597\n",
            "epoch:9600 ; loss:0.007907056249678135\n",
            "epoch:9800 ; loss:0.006751402746886015\n",
            "epoch:10000 ; loss:0.005322982091456652\n",
            "epoch:10200 ; loss:0.01067190058529377\n",
            "epoch:10400 ; loss:0.005645382218062878\n",
            "epoch:10600 ; loss:0.008898730389773846\n",
            "epoch:10800 ; loss:0.020944546908140182\n",
            "epoch:11000 ; loss:0.02016831748187542\n",
            "epoch:11200 ; loss:0.008137180469930172\n",
            "epoch:11400 ; loss:0.009900975041091442\n",
            "epoch:11600 ; loss:0.004450527019798756\n",
            "epoch:11800 ; loss:0.005173018202185631\n",
            "epoch:12000 ; loss:0.015184171497821808\n",
            "epoch:12200 ; loss:0.00978041347116232\n",
            "epoch:12400 ; loss:0.00516482861712575\n",
            "epoch:12600 ; loss:0.008431944996118546\n",
            "epoch:12800 ; loss:0.005888544954359531\n",
            "epoch:13000 ; loss:0.00606524758040905\n",
            "epoch:13200 ; loss:0.00607274891808629\n",
            "epoch:13400 ; loss:0.006703112740069628\n",
            "epoch:13600 ; loss:0.005184811539947987\n",
            "epoch:13800 ; loss:0.00512746861204505\n",
            "epoch:14000 ; loss:0.003012667642906308\n",
            "epoch:14200 ; loss:0.010636065155267715\n",
            "epoch:14400 ; loss:0.0024765683338046074\n",
            "epoch:14600 ; loss:0.002885771682485938\n",
            "epoch:14800 ; loss:0.011098294518887997\n",
            "epoch:15000 ; loss:0.0048125428147614\n",
            "epoch:15200 ; loss:0.0056232246570289135\n",
            "epoch:15400 ; loss:0.0048114340752363205\n",
            "epoch:15600 ; loss:0.006866832729429007\n",
            "epoch:15800 ; loss:0.005763686262071133\n",
            "epoch:16000 ; loss:0.0015339325182139874\n",
            "epoch:16200 ; loss:0.004628407768905163\n",
            "epoch:16400 ; loss:0.007014813367277384\n",
            "epoch:16600 ; loss:0.003914530389010906\n",
            "epoch:16800 ; loss:0.004509903956204653\n",
            "epoch:17000 ; loss:0.004074498079717159\n",
            "epoch:17200 ; loss:0.0021683506201952696\n",
            "epoch:17400 ; loss:0.004667551256716251\n",
            "epoch:17600 ; loss:0.01711338758468628\n",
            "epoch:17800 ; loss:0.0037473745178431273\n",
            "epoch:18000 ; loss:0.00802313070744276\n",
            "epoch:18200 ; loss:0.008050565607845783\n",
            "epoch:18400 ; loss:0.004823316354304552\n",
            "epoch:18600 ; loss:0.004527426790446043\n",
            "epoch:18800 ; loss:0.0049909926019608974\n",
            "epoch:19000 ; loss:0.005933865904808044\n",
            "epoch:19200 ; loss:0.009839811362326145\n",
            "epoch:19400 ; loss:0.016730619594454765\n",
            "epoch:19600 ; loss:0.005223553627729416\n",
            "epoch:19800 ; loss:0.009320043958723545\n",
            "epoch:20000 ; loss:0.004691397305577993\n",
            "epoch:20200 ; loss:0.002514686668291688\n",
            "epoch:20400 ; loss:0.004230946768075228\n",
            "epoch:20600 ; loss:0.005920322611927986\n",
            "epoch:20800 ; loss:0.0069515397772192955\n",
            "epoch:21000 ; loss:0.004240810871124268\n",
            "epoch:21200 ; loss:0.0031231942120939493\n",
            "epoch:21400 ; loss:0.006830972153693438\n",
            "epoch:21600 ; loss:0.029096374288201332\n",
            "epoch:21800 ; loss:0.003609114559367299\n",
            "epoch:22000 ; loss:0.005347818601876497\n",
            "epoch:22200 ; loss:0.0014504063874483109\n",
            "epoch:22400 ; loss:0.0019377589924260974\n",
            "epoch:22600 ; loss:0.00631911214441061\n",
            "epoch:22800 ; loss:0.0021812082268297672\n",
            "epoch:23000 ; loss:0.006175340618938208\n",
            "epoch:23200 ; loss:0.0023357977624982595\n",
            "epoch:23400 ; loss:0.0031536631286144257\n",
            "epoch:23600 ; loss:0.0019462903728708625\n",
            "epoch:23800 ; loss:0.0023794088046997786\n",
            "epoch:24000 ; loss:0.031441830098629\n",
            "epoch:24200 ; loss:0.004397120792418718\n",
            "epoch:24400 ; loss:0.006566280499100685\n",
            "epoch:24600 ; loss:0.007748397998511791\n",
            "epoch:24800 ; loss:0.0032647771295160055\n",
            "epoch:25000 ; loss:0.0025999615900218487\n",
            "epoch:25200 ; loss:0.0024359372910112143\n",
            "epoch:25400 ; loss:0.006489355582743883\n",
            "epoch:25600 ; loss:0.007965395227074623\n",
            "epoch:25800 ; loss:0.014778157696127892\n",
            "epoch:26000 ; loss:0.0034068755339831114\n",
            "epoch:26200 ; loss:0.008502479642629623\n",
            "epoch:26400 ; loss:0.0025559375062584877\n",
            "epoch:26600 ; loss:0.0034164804965257645\n",
            "epoch:26800 ; loss:0.0028901153709739447\n",
            "epoch:27000 ; loss:0.0033894022926688194\n",
            "epoch:27200 ; loss:0.0022576632909476757\n",
            "epoch:27400 ; loss:0.002501182956621051\n",
            "epoch:27600 ; loss:0.004281599540263414\n",
            "epoch:27800 ; loss:0.00363571522757411\n",
            "epoch:28000 ; loss:0.005550663452595472\n",
            "epoch:28200 ; loss:0.005153693724423647\n",
            "epoch:28400 ; loss:0.0045444173738360405\n",
            "epoch:28600 ; loss:0.003970704041421413\n",
            "epoch:28800 ; loss:0.0052837347611784935\n",
            "epoch:29000 ; loss:0.0026398547925055027\n",
            "epoch:29200 ; loss:0.0041761682368814945\n",
            "epoch:29400 ; loss:0.0055252667516469955\n",
            "epoch:29600 ; loss:0.008287183940410614\n",
            "epoch:29800 ; loss:0.004077168647199869\n",
            "epoch:30000 ; loss:0.004894538316875696\n",
            "epoch:30200 ; loss:0.005006118677556515\n",
            "epoch:30400 ; loss:0.005902886390686035\n",
            "epoch:30600 ; loss:0.002525630174204707\n",
            "epoch:30800 ; loss:0.0036746563855558634\n",
            "epoch:31000 ; loss:0.00510813994333148\n",
            "epoch:31200 ; loss:0.0025706735905259848\n",
            "epoch:31400 ; loss:0.005910378880798817\n",
            "epoch:31600 ; loss:0.006931720767170191\n",
            "epoch:31800 ; loss:0.00672532944008708\n",
            "epoch:32000 ; loss:0.002688855165615678\n",
            "epoch:32200 ; loss:0.003204645123332739\n",
            "epoch:32400 ; loss:0.007546020206063986\n",
            "epoch:32600 ; loss:0.0032771865371614695\n",
            "epoch:32800 ; loss:0.0034501191694289446\n",
            "epoch:33000 ; loss:0.001783317537046969\n",
            "epoch:33200 ; loss:0.0021033822558820248\n",
            "epoch:33400 ; loss:0.006298997905105352\n",
            "epoch:33600 ; loss:0.002935625845566392\n",
            "epoch:33800 ; loss:0.004934784024953842\n",
            "epoch:34000 ; loss:0.0009565406944602728\n",
            "epoch:34200 ; loss:0.0025501837953925133\n",
            "epoch:34400 ; loss:0.003814829746261239\n",
            "epoch:34600 ; loss:0.004417805466800928\n",
            "epoch:34800 ; loss:0.02184201404452324\n",
            "epoch:35000 ; loss:0.0017845737747848034\n",
            "epoch:35200 ; loss:0.003569268621504307\n",
            "epoch:35400 ; loss:0.003607554594054818\n",
            "epoch:35600 ; loss:0.007220097351819277\n",
            "epoch:35800 ; loss:0.004423112608492374\n",
            "epoch:36000 ; loss:0.0025011058896780014\n",
            "epoch:36200 ; loss:0.0030836653895676136\n",
            "epoch:36400 ; loss:0.003184173023328185\n",
            "epoch:36600 ; loss:0.0021553924307227135\n",
            "epoch:36800 ; loss:0.0010075540049001575\n",
            "epoch:37000 ; loss:0.0014074738137423992\n",
            "epoch:37200 ; loss:0.0026709132362157106\n",
            "epoch:37400 ; loss:0.004211358726024628\n",
            "epoch:37600 ; loss:0.0008590323850512505\n",
            "epoch:37800 ; loss:0.0021112817339599133\n",
            "epoch:38000 ; loss:0.026486165821552277\n",
            "epoch:38200 ; loss:0.0021431967616081238\n",
            "epoch:38400 ; loss:0.0026413726154714823\n",
            "epoch:38600 ; loss:0.0015743359690532088\n",
            "epoch:38800 ; loss:0.0021403729915618896\n",
            "epoch:39000 ; loss:0.005224096123129129\n",
            "epoch:39200 ; loss:0.0018656263127923012\n",
            "epoch:39400 ; loss:0.0033891364000737667\n",
            "epoch:39600 ; loss:0.002442119177430868\n",
            "epoch:39800 ; loss:0.0033034358639270067\n",
            "epoch:40000 ; loss:0.005629339255392551\n",
            "epoch:40200 ; loss:0.007487826514989138\n",
            "epoch:40400 ; loss:0.003101831069216132\n",
            "epoch:40600 ; loss:0.0012285721022635698\n",
            "epoch:40800 ; loss:0.005868111737072468\n",
            "epoch:41000 ; loss:0.0007131349993869662\n",
            "epoch:41200 ; loss:0.0026507910806685686\n",
            "epoch:41400 ; loss:0.0035697431303560734\n",
            "epoch:41600 ; loss:0.003475228790193796\n",
            "epoch:41800 ; loss:0.010017851367592812\n",
            "epoch:42000 ; loss:0.002670208690688014\n",
            "epoch:42200 ; loss:0.004355883225798607\n",
            "epoch:42400 ; loss:0.002086245222017169\n",
            "epoch:42600 ; loss:0.006356734316796064\n",
            "epoch:42800 ; loss:0.002597376238554716\n",
            "epoch:43000 ; loss:0.0015797971282154322\n",
            "epoch:43200 ; loss:0.0020795108284801245\n",
            "epoch:43400 ; loss:0.0019051814451813698\n",
            "epoch:43600 ; loss:0.004200384486466646\n",
            "epoch:43800 ; loss:0.005771012045443058\n",
            "epoch:44000 ; loss:0.004488250706344843\n",
            "epoch:44200 ; loss:0.0019641683902591467\n",
            "epoch:44400 ; loss:0.002891849959269166\n",
            "epoch:44600 ; loss:0.004486863035708666\n",
            "epoch:44800 ; loss:0.007841764949262142\n",
            "epoch:45000 ; loss:0.0016155890189111233\n",
            "epoch:45200 ; loss:0.005547362845391035\n",
            "epoch:45400 ; loss:0.0025214250199496746\n",
            "epoch:45600 ; loss:0.01594679057598114\n",
            "epoch:45800 ; loss:0.009235288016498089\n",
            "epoch:46000 ; loss:0.008821322582662106\n",
            "epoch:46200 ; loss:0.004861755296587944\n",
            "epoch:46400 ; loss:0.006050280760973692\n",
            "epoch:46600 ; loss:0.003199632978066802\n",
            "epoch:46800 ; loss:0.004097605589777231\n",
            "epoch:47000 ; loss:0.0026511044707149267\n",
            "epoch:47200 ; loss:0.0015033988747745752\n",
            "epoch:47400 ; loss:0.0034141186624765396\n",
            "epoch:47600 ; loss:0.005457330495119095\n",
            "epoch:47800 ; loss:0.00371836987324059\n",
            "epoch:48000 ; loss:0.002316063502803445\n",
            "epoch:48200 ; loss:0.0015686328988522291\n",
            "epoch:48400 ; loss:0.0018058617133647203\n",
            "epoch:48600 ; loss:0.009717726148664951\n",
            "epoch:48800 ; loss:0.0030767247080802917\n",
            "epoch:49000 ; loss:0.003139825537800789\n",
            "epoch:49200 ; loss:0.003455039346590638\n",
            "epoch:49400 ; loss:0.0020441424567252398\n",
            "epoch:49600 ; loss:0.0016198329394683242\n",
            "epoch:49800 ; loss:0.005687505938112736\n",
            "epoch:50000 ; loss:0.002265259390696883\n",
            "epoch:50200 ; loss:0.0029768990352749825\n",
            "epoch:50400 ; loss:0.010253756307065487\n",
            "epoch:50600 ; loss:0.002790809143334627\n",
            "epoch:50800 ; loss:0.001132951583713293\n",
            "epoch:51000 ; loss:0.0009581397171132267\n",
            "epoch:51200 ; loss:0.003206794848665595\n",
            "epoch:51400 ; loss:0.028695600107312202\n",
            "epoch:51600 ; loss:0.0014327599201351404\n",
            "epoch:51800 ; loss:0.003550182096660137\n",
            "epoch:52000 ; loss:0.002678368706256151\n",
            "epoch:52200 ; loss:0.002286639530211687\n",
            "epoch:52400 ; loss:0.023308074101805687\n",
            "epoch:52600 ; loss:0.000799350964371115\n",
            "epoch:52800 ; loss:0.0016937794862315059\n",
            "epoch:53000 ; loss:0.0028633454348891973\n",
            "epoch:53200 ; loss:0.0015102365287020802\n",
            "epoch:53400 ; loss:0.0020465990528464317\n",
            "epoch:53600 ; loss:0.004347901325672865\n",
            "epoch:53800 ; loss:0.0007322857272811234\n",
            "epoch:54000 ; loss:0.009264716878533363\n",
            "epoch:54200 ; loss:0.0026000840589404106\n",
            "epoch:54400 ; loss:0.0019937297329306602\n",
            "epoch:54600 ; loss:0.024717988446354866\n",
            "epoch:54800 ; loss:0.004963281564414501\n",
            "epoch:55000 ; loss:0.0018892966909334064\n",
            "epoch:55200 ; loss:0.0038747608195990324\n",
            "epoch:55400 ; loss:0.003587784245610237\n",
            "epoch:55600 ; loss:0.003373539773747325\n",
            "epoch:55800 ; loss:0.004117194097489119\n",
            "epoch:56000 ; loss:0.0031460467725992203\n",
            "epoch:56200 ; loss:0.03772659972310066\n",
            "epoch:56400 ; loss:0.0014169671339914203\n",
            "epoch:56600 ; loss:0.006251668091863394\n",
            "epoch:56800 ; loss:0.001608599559403956\n",
            "epoch:57000 ; loss:0.004503809381276369\n",
            "epoch:57200 ; loss:0.006427177228033543\n",
            "epoch:57400 ; loss:0.003095798660069704\n",
            "epoch:57600 ; loss:0.0019361487356945872\n",
            "epoch:57800 ; loss:0.005412069149315357\n",
            "epoch:58000 ; loss:0.003759605111554265\n",
            "epoch:58200 ; loss:0.003926719538867474\n",
            "epoch:58400 ; loss:0.00261289463378489\n",
            "epoch:58600 ; loss:0.005349757149815559\n",
            "epoch:58800 ; loss:0.00047208325122483075\n",
            "epoch:59000 ; loss:0.010738857090473175\n",
            "epoch:59200 ; loss:0.001635493477806449\n",
            "epoch:59400 ; loss:0.0025312781799584627\n",
            "epoch:59600 ; loss:0.002430814318358898\n",
            "epoch:59800 ; loss:0.0016154095064848661\n",
            "epoch:60000 ; loss:0.002135966205969453\n",
            "epoch:60200 ; loss:0.0020357556641101837\n",
            "epoch:60400 ; loss:0.0008845687843859196\n",
            "epoch:60600 ; loss:0.002225927310064435\n",
            "epoch:60800 ; loss:0.0013301809085533023\n",
            "epoch:61000 ; loss:0.0007440302288159728\n",
            "epoch:61200 ; loss:0.004158062394708395\n",
            "epoch:61400 ; loss:0.0023384946398437023\n",
            "epoch:61600 ; loss:0.0019475899171084166\n",
            "epoch:61800 ; loss:0.002133528469130397\n",
            "epoch:62000 ; loss:0.006947977002710104\n",
            "epoch:62200 ; loss:0.003470989177003503\n",
            "epoch:62400 ; loss:0.002486051060259342\n",
            "epoch:62600 ; loss:0.012324688956141472\n",
            "epoch:62800 ; loss:0.0023772702552378178\n",
            "epoch:63000 ; loss:0.0008232418913394213\n",
            "epoch:63200 ; loss:0.0011239787563681602\n",
            "epoch:63400 ; loss:0.0032048760913312435\n",
            "epoch:63600 ; loss:0.0015007727779448032\n",
            "epoch:63800 ; loss:0.003652285085991025\n",
            "epoch:64000 ; loss:0.0026938386727124453\n",
            "epoch:64200 ; loss:0.00229008705355227\n",
            "epoch:64400 ; loss:0.002244030125439167\n",
            "epoch:64600 ; loss:0.002417355077341199\n",
            "epoch:64800 ; loss:0.005607454106211662\n",
            "epoch:65000 ; loss:0.005195149686187506\n",
            "epoch:65200 ; loss:0.0030637457966804504\n",
            "epoch:65400 ; loss:0.0020484556443989277\n",
            "epoch:65600 ; loss:0.0012205220991745591\n",
            "epoch:65800 ; loss:0.0017134679947048426\n",
            "epoch:66000 ; loss:0.0016554832691326737\n",
            "epoch:66200 ; loss:0.003082864684984088\n",
            "epoch:66400 ; loss:0.010762833058834076\n",
            "epoch:66600 ; loss:0.0016081116627901793\n",
            "epoch:66800 ; loss:0.002842961810529232\n",
            "epoch:67000 ; loss:0.0017965181032195687\n",
            "epoch:67200 ; loss:0.0064267055131495\n",
            "epoch:67400 ; loss:0.0018459904240444303\n",
            "epoch:67600 ; loss:0.0018789779860526323\n",
            "epoch:67800 ; loss:0.003634596010670066\n",
            "epoch:68000 ; loss:0.002189815742895007\n",
            "epoch:68200 ; loss:0.016218189150094986\n",
            "epoch:68400 ; loss:0.0031214654445648193\n",
            "epoch:68600 ; loss:0.0021118037402629852\n",
            "epoch:68800 ; loss:0.0012580183101817966\n",
            "epoch:69000 ; loss:0.0007687112083658576\n",
            "epoch:69200 ; loss:0.0033559738658368587\n",
            "epoch:69400 ; loss:0.002860285807400942\n",
            "epoch:69600 ; loss:0.002434661379083991\n",
            "epoch:69800 ; loss:0.002037664409726858\n",
            "epoch:70000 ; loss:0.003246869659051299\n",
            "epoch:70200 ; loss:0.03205611929297447\n",
            "epoch:70400 ; loss:0.0027649234980344772\n",
            "epoch:70600 ; loss:0.017015330493450165\n",
            "epoch:70800 ; loss:0.005436749197542667\n",
            "epoch:71000 ; loss:0.0009792748605832458\n",
            "epoch:71200 ; loss:0.004901123233139515\n",
            "epoch:71400 ; loss:0.001286797458305955\n",
            "epoch:71600 ; loss:0.004126672632992268\n",
            "epoch:71800 ; loss:0.0009219836792908609\n",
            "epoch:72000 ; loss:0.0016239056130871177\n",
            "epoch:72200 ; loss:0.01031555887311697\n",
            "epoch:72400 ; loss:0.0010418323799967766\n",
            "epoch:72600 ; loss:0.0032485495321452618\n",
            "epoch:72800 ; loss:0.0012321732938289642\n",
            "epoch:73000 ; loss:0.004396482836455107\n",
            "epoch:73200 ; loss:0.004167477134615183\n",
            "epoch:73400 ; loss:0.0019477561581879854\n",
            "epoch:73600 ; loss:0.0025172217283397913\n",
            "epoch:73800 ; loss:0.0013279429404065013\n",
            "epoch:74000 ; loss:0.00466731283813715\n",
            "epoch:74200 ; loss:0.007368369027972221\n",
            "epoch:74400 ; loss:0.0009593693539500237\n",
            "epoch:74600 ; loss:0.002709008753299713\n",
            "epoch:74800 ; loss:0.0038995675276964903\n",
            "epoch:75000 ; loss:0.0024712372105568647\n",
            "epoch:75200 ; loss:0.0018103515030816197\n",
            "epoch:75400 ; loss:0.001631211955100298\n",
            "epoch:75600 ; loss:0.006100473925471306\n",
            "epoch:75800 ; loss:0.005700422450900078\n",
            "epoch:76000 ; loss:0.0022247720044106245\n",
            "epoch:76200 ; loss:0.0017856884514912963\n",
            "epoch:76400 ; loss:0.0009116171859204769\n",
            "epoch:76600 ; loss:0.0018960876623168588\n",
            "epoch:76800 ; loss:0.002129520522430539\n",
            "epoch:77000 ; loss:0.0024484950117766857\n",
            "epoch:77200 ; loss:0.0025574639439582825\n",
            "epoch:77400 ; loss:0.0017884316621348262\n",
            "epoch:77600 ; loss:0.0005586466286331415\n",
            "epoch:77800 ; loss:0.002462442498654127\n",
            "epoch:78000 ; loss:0.004685379099100828\n",
            "epoch:78200 ; loss:0.0027669034898281097\n",
            "epoch:78400 ; loss:0.002046517562121153\n",
            "epoch:78600 ; loss:0.0020889509469270706\n",
            "epoch:78800 ; loss:0.0016368875512853265\n",
            "epoch:79000 ; loss:0.006057986989617348\n",
            "epoch:79200 ; loss:0.004504421725869179\n",
            "epoch:79400 ; loss:0.0028795297257602215\n",
            "epoch:79600 ; loss:0.0048745423555374146\n",
            "epoch:79800 ; loss:0.011225925758481026\n",
            "epoch:80000 ; loss:0.002887226175516844\n",
            "epoch:80200 ; loss:0.002372913295403123\n",
            "epoch:80400 ; loss:0.002397262491285801\n",
            "epoch:80600 ; loss:0.0016859547467902303\n",
            "epoch:80800 ; loss:0.002140986267477274\n",
            "epoch:81000 ; loss:0.0024995135609060526\n",
            "epoch:81200 ; loss:0.0012931807432323694\n",
            "epoch:81400 ; loss:0.002673068083822727\n",
            "epoch:81600 ; loss:0.0012171132257208228\n",
            "epoch:81800 ; loss:0.0028135289903730154\n",
            "epoch:82000 ; loss:0.020962292328476906\n",
            "epoch:82200 ; loss:0.0010284583549946547\n",
            "epoch:82400 ; loss:0.0023283548653125763\n",
            "epoch:82600 ; loss:0.0003181595529895276\n",
            "epoch:82800 ; loss:0.001308694132603705\n",
            "epoch:83000 ; loss:0.0020672865211963654\n",
            "epoch:83200 ; loss:0.003351469524204731\n",
            "epoch:83400 ; loss:0.0009894710965454578\n",
            "epoch:83600 ; loss:0.0005526855238713324\n",
            "epoch:83800 ; loss:0.0010866993106901646\n",
            "epoch:84000 ; loss:0.0028241195250302553\n",
            "epoch:84200 ; loss:0.002403995953500271\n",
            "epoch:84400 ; loss:0.0008994402596727014\n",
            "epoch:84600 ; loss:0.010512690991163254\n",
            "epoch:84800 ; loss:0.0020095768850296736\n",
            "epoch:85000 ; loss:0.0027619083411991596\n",
            "epoch:85200 ; loss:0.016458583995699883\n",
            "epoch:85400 ; loss:0.0008611311786808074\n",
            "epoch:85600 ; loss:0.0027716723270714283\n",
            "epoch:85800 ; loss:0.003741208929568529\n",
            "epoch:86000 ; loss:0.0024263171944767237\n",
            "epoch:86200 ; loss:0.0030803086701780558\n",
            "epoch:86400 ; loss:0.0018839022377505898\n",
            "epoch:86600 ; loss:0.004469909239560366\n",
            "epoch:86800 ; loss:0.0027713822200894356\n",
            "epoch:87000 ; loss:0.001997500890865922\n",
            "epoch:87200 ; loss:0.0009501712629571557\n",
            "epoch:87400 ; loss:0.0008264151983894408\n",
            "epoch:87600 ; loss:0.0018048710189759731\n",
            "epoch:87800 ; loss:0.0022342526353895664\n",
            "epoch:88000 ; loss:0.003880012547597289\n",
            "epoch:88200 ; loss:0.0003247660060878843\n",
            "epoch:88400 ; loss:0.011988436803221703\n",
            "epoch:88600 ; loss:0.0026836672332137823\n",
            "epoch:88800 ; loss:0.0037000542506575584\n",
            "epoch:89000 ; loss:0.0050710272043943405\n",
            "epoch:89200 ; loss:0.002602527616545558\n",
            "epoch:89400 ; loss:0.0033759858924895525\n",
            "epoch:89600 ; loss:0.0015838365070521832\n",
            "epoch:89800 ; loss:0.0016241860575973988\n",
            "epoch:90000 ; loss:0.002893793862313032\n",
            "epoch:90200 ; loss:0.0013477839529514313\n",
            "epoch:90400 ; loss:0.001775050419382751\n",
            "epoch:90600 ; loss:0.00030343985417857766\n",
            "epoch:90800 ; loss:0.0016755263786762953\n",
            "epoch:91000 ; loss:0.002826911397278309\n",
            "epoch:91200 ; loss:0.0008132807561196387\n",
            "epoch:91400 ; loss:0.00206194375641644\n",
            "epoch:91600 ; loss:0.0029409050475806\n",
            "epoch:91800 ; loss:0.004557126667350531\n",
            "epoch:92000 ; loss:0.0031442006584256887\n",
            "epoch:92200 ; loss:0.006214790511876345\n",
            "epoch:92400 ; loss:0.0036031012423336506\n",
            "epoch:92600 ; loss:0.0026756857987493277\n",
            "epoch:92800 ; loss:0.0023887460120022297\n",
            "epoch:93000 ; loss:0.003055794630199671\n",
            "epoch:93200 ; loss:0.0013998185750097036\n",
            "epoch:93400 ; loss:0.0002990356588270515\n",
            "epoch:93600 ; loss:0.0017247290816158056\n",
            "epoch:93800 ; loss:0.0009558796300552785\n",
            "epoch:94000 ; loss:0.0019591792952269316\n",
            "epoch:94200 ; loss:0.008760732598602772\n",
            "epoch:94400 ; loss:0.0026929574087262154\n",
            "epoch:94600 ; loss:0.01698443852365017\n",
            "epoch:94800 ; loss:0.002134090755134821\n",
            "epoch:95000 ; loss:0.00332960719242692\n",
            "epoch:95200 ; loss:0.002079176949337125\n",
            "epoch:95400 ; loss:0.008870711550116539\n",
            "epoch:95600 ; loss:0.005144030787050724\n",
            "epoch:95800 ; loss:0.006358040031045675\n",
            "epoch:96000 ; loss:0.0013799536973237991\n",
            "epoch:96200 ; loss:0.000850691634695977\n",
            "epoch:96400 ; loss:0.0020169843919575214\n",
            "epoch:96600 ; loss:0.009329145774245262\n",
            "epoch:96800 ; loss:0.0027827764861285686\n",
            "epoch:97000 ; loss:0.003478867234662175\n",
            "epoch:97200 ; loss:0.002438032068312168\n",
            "epoch:97400 ; loss:0.0027428644243627787\n",
            "epoch:97600 ; loss:0.0014552820939570665\n",
            "epoch:97800 ; loss:0.0019104237435385585\n",
            "epoch:98000 ; loss:0.0028111401479691267\n",
            "epoch:98200 ; loss:0.001990922261029482\n",
            "epoch:98400 ; loss:0.0015253889141604304\n",
            "epoch:98600 ; loss:0.003470691153779626\n",
            "epoch:98800 ; loss:0.0020742195192724466\n",
            "epoch:99000 ; loss:0.001352178631350398\n",
            "epoch:99200 ; loss:0.0036654844880104065\n",
            "epoch:99400 ; loss:0.0010394083801656961\n",
            "epoch:99600 ; loss:0.0011815497418865561\n",
            "epoch:99800 ; loss:0.00032130960607901216\n",
            "epoch:100000 ; loss:0.0025937745813280344\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "65m2Os7h-qEt",
        "outputId": "bc1d4253-06db-43ef-a30d-8aba52413304"
      },
      "source": [
        "myNet(torch.zeros(2,1))"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[  0.0000, -47.6527],\n",
              "        [  0.0000, -47.6527]], grad_fn=<LogSoftmaxBackward0>)"
            ]
          },
          "metadata": {},
          "execution_count": 7
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "LBizkBSbWESg",
        "outputId": "610f422b-7c7b-42b9-eae2-bac6d5f45f63"
      },
      "source": [
        "myNet(torch.ones(2,1))"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[-45.7640,   0.0000],\n",
              "        [-45.7640,   0.0000]], grad_fn=<LogSoftmaxBackward>)"
            ]
          },
          "metadata": {},
          "execution_count": 106
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "0dlAqBqgc7o2",
        "outputId": "b7498950-d7d1-4f0e-e015-ae7681586c0d"
      },
      "source": [
        "myNet(torch.ones(2,1)-0.2)"
      ],
      "execution_count": null,
      "outputs": [
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": [
              "tensor([[-45.3648,   0.0000],\n",
              "        [-45.3648,   0.0000]], grad_fn=<LogSoftmaxBackward>)"
            ]
          },
          "metadata": {},
          "execution_count": 107
        }
      ]
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "5VeqwifodqGN"
      },
      "source": [
        "torch.onnx.export(myNet,                       # model being run\n",
        "  torch.Tensor(np.ones((10,1), dtype=np.float32)),                         # model input (or a tuple for multiple inputs)\n",
        "  \"model.onnx\",            # where to save the model (can be a file or file-like object)\n",
        "  export_params=True,        # store the trained parameter weights inside the model file\n",
        "  opset_version=9,           # the ONNX version to export the model to\n",
        "  do_constant_folding=True,  # whether to execute constant folding for optimization\n",
        "  input_names = ['inputLayer'],       # the model's input names\n",
        "  output_names = ['outputLayer']       # the model's output names\n",
        ")\n"
      ],
      "execution_count": 8,
      "outputs": []
    },
    {
      "cell_type": "code",
      "metadata": {
        "id": "oYMwL94eeq7V"
      },
      "source": [
        ""
      ],
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "from google.colab import drive\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "id": "pKfykhBeQ1Vh"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}